package com.ypinkj.app.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ypinkj.app.entity.UResumeExperience;
import com.ypinkj.app.entity.UResumeJobhunting;
import com.ypinkj.app.entity.UResumeProgress;
import com.ypinkj.app.entity.UResumeWork;
import com.ypinkj.app.mapper.UResumeProgressMapper;
import com.ypinkj.app.utils.resultutils.Result;
import com.ypinkj.app.utils.resultutils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 *  个人特长
 * </p>
 *
 * @author LF
 * @since 2020-09-29
 */
@Api(tags = "个人特长")
@RestController
@RequestMapping("/u-resume-progress")
public class UResumeProgressController {

    @Autowired
    UResumeProgressMapper resumeProgressMapper;

    @ApiOperation(value = "保存")
    @PutMapping
    public Result save(@RequestBody UResumeProgress resumeProgress){
        String id = resumeProgress.getId();
        if (id==null){
            return resumeProgressMapper.insert(resumeProgress)>0 ? ResultUtil.success(resumeProgress) : ResultUtil.errorMsg();
        }else {
            int i = resumeProgressMapper.UpdateUResumeWorkById(resumeProgress);
            return i>0 ?ResultUtil.success() : ResultUtil.errorMsg();
        }
    }

    @ApiOperation(value = "列表")
    @GetMapping
    public Result getList(String userid){
        wrapper.eq(UResumeProgress::getUserid,userid);
        List<UResumeProgress> list = resumeProgressMapper.selectList(wrapper);
        return list.size()>0 ?ResultUtil.success(list) : ResultUtil.errorMsg();
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping
    public Result deleteById(String id){
        int i = resumeProgressMapper.deleteById(id);
        return i>0 ?ResultUtil.success() : ResultUtil.errorMsg();
    }

    @ApiOperation(value = "根据id修改")
    @PostMapping
    public Result updateById(UResumeProgress resumeWork){
        int i = resumeProgressMapper.UpdateUResumeWorkById(resumeWork);
        return i>0 ?ResultUtil.success() : ResultUtil.errorMsg();
    }

    private static LambdaQueryWrapper<UResumeProgress> wrapper = new LambdaQueryWrapper<>();

}
